#include <func.h>
int main (int argc,char *argv[])
{
    ARGS_CHECK(argc,3);
    int fdr = open(argv[1],O_RDONLY);
    int fdw = open(argv[2],O_WRONLY);
    printf("I am chat1\n");
    char buf[128] = {0};
    int ret;
    fd_set rdset;
    while(1)
    {
        FD_ZERO(&rdset);
        FD_SET(STDIN_FILENO,&rdset);//添加监听
        FD_SET(fdr,&rdset);
        struct timeval timeout;
        timeout.tv_sec = 2;
        timeout.tv_usec = 500000;
        ret = select(fdr+1,&rdset,NULL,NULL,&timeout);
        if(ret==0)
        {
            puts("timeout!");
            continue;
        }
        if(FD_ISSET(STDIN_FILENO,&rdset))//查看集合是否就绪
        {
            memset(buf,0,sizeof(buf));
            int ret=read(STDIN_FILENO,buf,sizeof(buf));
            if(ret==0)
            {
                puts("end/n");//ctrl +c;
                break;
            }
            write(fdw,buf,strlen(buf)-1);    
        }
                if(FD_ISSET(fdr,&rdset))
        {
            memset(buf,0,sizeof(buf));
            int ret=read(fdr,buf,sizeof(buf));
            if(ret==0)
            {
                puts("你是个好人");//ctrl +d;
                break;
            }
            printf("buf= %s\n",buf);  
        }

    }
    return 0;

}